
const request = (url, method, data={}) => {
  return new Promise((resolve, reject) => {
    //定义baseUrl，并获取缓存中的token
    let baseUrl = 'http://127.0.0.1:3000'
    // let baseUrl = 'http://123.249.111.34:3000'
    let _url = baseUrl + url;
    let token = ''
    if (wx.getStorageSync('token') !== null) {
      token = wx.getStorageSync('token')
    }
    wx.request({
      url: _url,
      data: data,
      method: method,
      header: {
        'content-type': 'application/json',
        'Authorization': 'Bearer ' + token
      },
      success: res => {
        // console.log(res);
        if (res.statusCode==500&&res.data.message&&res.data.message=="jwt expired") {
          reject({status:500,msg:"身份过期请重新登录"})
        }
        resolve(res.data)
      },
      fail: err => {
        console.log("服务器异常了，请检查");
        reject({status:500,msg:"服务器异常了，请检查"})
      }
    })
  })
}
module.exports  = request;